<%--
  Created by IntelliJ IDEA.
  User: ZhuChunXiao
  Date: 2017/5/26
  Time: 9:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<div class="row">
  <div class="col-lg-12">
    <div class="panel">
      <div class="panel-heading">
        <h3 class="panel-title">培训登记表</h3>
      </div>

      <!-- BASIC FORM ELEMENTS -->
      <!--===================================================-->
      <form id="form_train_input" class="panel-body form-horizontal form-padding">
        <input type="hidden" name="keyId" id="keyId" value="${train.id}" />
        <input type="hidden" name="curDutyId" id="curDutyId" value=""/>


        <div class="form-group">
          <label class="col-md-2 control-label">培训主题<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-6">
            <input disabled type="text" id="theme" name="theme" class="form-control" placeholder="请输入培训主题" value="${train.theme}">
          </div>
        </div>

        <div class="form-group">
          <label class="col-md-2 control-label">培训类型<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-6">
            <input disabled type="text" id="type" name="type" class="form-control" placeholder="请输入培训主题" value="${train.type.name}">
          </div>
        </div>

        <div class="form-group">
          <label class="col-md-2 control-label">培训内容<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-6">
            <input disabled type="text" id="content" name="content" class="form-control" placeholder="请输入培训内容" value="${train.content}">
          </div>
        </div>

        <div class="form-group div-Hidden">
          <label class="col-md-2 control-label">培训开始日期<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-2">
            <div class="input-group date">
              <input type="text" class="form-control" id="cycleStart" name="cycleStart" placeholder="请选择培训开始日期" disabled
                     value=<fmt:formatDate pattern="yyyy-MM-dd" value="${train.cycleStart}" /> >
              <span class="input-group-addon"><i class="ti-calendar"></i></span>
            </div>
          </div>
          <label class="col-md-2 control-label">培训结束日期<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-2">
            <div class="input-group date">
              <input type="text" class="form-control" id="cycleEnd" name="cycleEnd" placeholder="请选择培训结束日期" disabled
                     value=<fmt:formatDate pattern="yyyy-MM-dd" value="${train.cycleEnd}" /> >
              <span class="input-group-addon"><i class="ti-calendar"></i></span>
            </div>
          </div>
        </div>

        <div class="form-group">
          <label class="col-md-2 control-label">培训讲师<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-6">
            <input disabled type="text" id="lecturer" name="lecturer" class="form-control" placeholder="请输入培训讲师" value="${train.lecturer}">
          </div>
        </div>

        <div class="form-group">
          <label class="col-md-2 control-label">
            <%--<a href="javascript:void(0);" onclick="fn_members_dialog_select()" style="color: #0a6dbd">参与人员</a>--%>
            参与人员
            <i class="fa fa-asterisk txt-color-red"></i>
          </label>
          <div class="col-md-6">
            <input type="text" id="userNames" name="userNames" class="form-control" placeholder="请选择参与人员" disabled
                   value="<c:forEach var="item" items="${train.joinUsers}" varStatus="status">${item.name}<c:if test="${!status.last}">,</c:if></c:forEach>">
            <input type="hidden" id="userIds" name="userIds" disabled
                   value="<c:forEach var="item" items="${train.joinUsers}" varStatus="status">${item.id}<c:if test="${!status.last}">,</c:if></c:forEach>">
          </div>
        </div>

        <c:if test="${train.finish&&train.finishState==1}">
          <div class="form-group">
            <label class="col-md-2 control-label">培训总结<i class="fa fa-asterisk txt-color-red"></i></label>
            <div class="col-md-6">
              <input disabled type="text" id="summary" name="summary" class="form-control" value="${train.summary}">
            </div>
          </div>
        </c:if>
        <c:if test="${train.finish&&train.finishState==2}">
          <div class="form-group">
            <label class="col-md-2 control-label">取消原因<i class="fa fa-asterisk txt-color-red"></i></label>
            <div class="col-md-6">
              <input disabled type="text" id="cancelReason" name="cancelReason" class="form-control" value="${train.cancelReason}">
            </div>
          </div>
        </c:if>


        <div class="form-group">
          <label class="col-md-2 control-label">提交人</label>
          <div class="col-md-2">
            <p class="form-control-static">${train.creater.name}</p>
          </div>
          <label class="col-md-2 control-label">提交日期</label>
          <div class="col-md-2">
            <p class="form-control-static"><fmt:formatDate pattern="yyyy-MM-dd" value="${train.createTime}" /></p>
          </div>
        </div>

        <c:if test='${(train.processState=="Running" || train.processState=="Backed") && stepNo !=1 && stepNo !=0}'>
          <div class="form-group" id="comment">
            <label class="col-md-2 control-label">审批意见</label>
            <div class="col-md-6">
              <textarea name="editor" id="editor" style="height:200px;"></textarea>
            </div>
          </div>
        </c:if>

        <div class="flow">
          <div class="panel-footer">
            <a class="btn btn-default" id="apply-re-common6" href="javascript:void(0)">
              <i class="fa fa-lg fa-mail-reply"></i> 返回
            </a>
            <a class="btn btn-default" key="ajax_edit6" href="javascript:void(0);" ${isEdit}>
              <i class="fa fa-lg fa-edit"></i> 编辑
            </a>
          </div>

          <div class="f_title"><i class="right" id="flow6"></i>流程信息</div>
          <div class="f_content" style="display:none">
            <div id="showFlow6"></div>
          </div>
          <div class="f_title"><i class="right" id="next6"></i>下一步骤提示</div>
          <div class="f_content" style="display:none">
            <div id="showNext6"></div>
          </div>
        </div>
        
      </form>
      <!--===================================================-->
      <!-- END BASIC FORM ELEMENTS -->
      
    </div>
  </div>
</div>

<script>
  var index = "${index}";
  var todo = "${todo}";
  var remind = "${remind}";
  var record = "${record}";
  var draft =  "${draft}";
  var stepNo = "${stepNo}";

  $(function(){
    $("#tableWidth").val($("#tempWidth").width());

    loadURL("<%=path%>/com/running/workflow?bussinessId="+$("#form_train_input #keyId").val()+"&type=flow",$('#showFlow6'));
    loadURL("<%=path%>/com/running/workflow?bussinessId="+$("#form_train_input #keyId").val()+"&type=next",$('#showNext6'));
    __ajax_post("<%=path%>/com/running/operateType",{keyId: $("#form_train_input #keyId").val()},function(pdata){
      var showDuty = false;
      var area = $("form .panel-footer");
      var edit = null;
      if (stepNo == 1){
        return false;
      }
      $(pdata.datarows).each(function(i,v){
        var str = '<a id="left_foot_btn_'+ v.action+'" class="btn btn-warning" href="javascript:void(0);"><i class="fa fa-upload">'+ v.name+'</i></a>&nbsp;';
        $(area).append(str);
        if(v.action == "approve" || v.action=="sendback"  || v.action=="deny"){
          showDuty = true;
        }
      });
      if(showDuty == true){
        var pdata = {
          keyId: $("#form_train_input #keyId").val(),
          entityName: "com.fz.us.oa.core.entity.com.Train"
        };
        multiDuty(pdata);
      }else{
        $('#comment').hide();
      }
      if($(':visible#editor').length == 1){
        edit  = new UE.ui.Editor();
        edit.render('editor');
        /*
         edit.ready(function() {
         edit.setContent("");
         });*/
      }
      //通过
      $("#left_foot_btn_approve").off("click").on("click",function(){
        var comment = "";
        if(edit != null){
          comment = encodeURIComponent(edit.getContent());
        }
        if($.trim(comment) == ""){
          alert("请填写审批意见");
          return false;
        }
        __form_save("form_train_input","<%=path%>/com/train/approve?comment="+comment,function(){
          $("#apply-re-common6").trigger("click");
        })
      });
      //退回
      $("#left_foot_btn_sendback").off("click").on("click",function(){
        var comment = "";
        if(edit != null){
          comment = encodeURIComponent(edit.getContent());
        }
        if($.trim(comment) == ""){
          alert("请填写审批意见");
          return false;
        }
        var vActionUrl="<%=path%>/com/train/back?comment="+comment+"&curDutyId="+$('#curDutyId').val();
        var data={keyId:$("#form_train_input #keyId").val()};
        __ajax_post(vActionUrl,data,function(pdata){
          __toastr(pdata);
          $("#apply-re-common6").trigger("click");
        });
      });
      //否决
      $("#left_foot_btn_deny").off("click").on("click",function(){
        var comment = "";
        if(edit != null){
          comment = encodeURIComponent(edit.getContent());
        }
        if($.trim(comment) == ""){
          alert("请填写审批意见");
          return false;
        }
        var vActionUrl="<%=path%>/com/train/deny?comment="+comment+"&curDutyId="+$('#curDutyId').val();
        var data={keyId:$("#form_train_input #keyId").val()};
        __ajax_post(vActionUrl,data,function(pdata){
          __toastr(pdata);
          $("#apply-re-common6").trigger("click");
        });
      });
    });

    //流程信息展开
    $('#flow6,#next6').click(function(){
      if($(this).hasClass("right")){
        $(this).removeClass("right").addClass("down");
        $(this).parent(".f_title").next("div.f_content").show();
      }else{
        $(this).removeClass("down").addClass("right");
        $(this).parent(".f_title").next("div.f_content").hide();
      }
    });

  });

  //编辑
  $("a[key='ajax_edit6']").unbind("click").bind("click",function(){
    loadURL("<%=path%>/com/train/input?keyId="+$("#keyId").val()+"&draft="+draft+"&todo="+todo+"&remind="+remind+"&record="+record+"&index="+index,$('#page-content'));
  });


  //返回视图
  $("#apply-re-common6").click(function(){
    if($("#form_personnelinfo_input").size()>0){
      var parentId=$("#form_personnelinfo_input #keyId").val();
      var table_global_width = $("#s1").is(":visible") ? $("#s1").width() : $("#s6").width();
      $('div').data("table_global_width", table_global_width);
      loadURL("<%=path%>/com/train/toList?parentId="+parentId,$('#s6'));
    }else{
      if(index==1){
        loadURL("menu/dashboard",$('#page-content'));
      }else if(todo==1){
        loadURL("menu/toDo",$('#page-content'));
      }else if(remind==1){
        loadURL("menu/remind",$('#page-content'));
      }else if(record==1){
        loadURL("menu/taskRecord?type=1",$('#page-content'));
      }else if(record==2){
        loadURL("menu/taskRecord?type=2",$('#page-content'));
      }else if(draft==1){
        loadURL("menu/draft",$('#page-content'));
      }else{
        returnToHashUrl()
      }
    }
  });

</script>




